#include <iostream>

#include "AllocationTest.h"
#include "Timer.h"
#include "Config.h"


//struct AllocationTestStruct
//{
//	int x;
//	float y;
//};


struct AllocationTestStruct
{
	float x;
	float y;
	float z;
	char pad[58];
	//char pad[1494];
	float w;
};

		

namespace Test
{


void AllocationTest()
{
	Timer t;
	const size_t N = 10;
	const size_t M = 10;
	AllocationTestStruct* vec[N];
	for(size_t i=0; i<N; ++i)
		vec[i] = 0;

	t.Start();
	for(size_t j = 0; j<M ; ++j)
	{
		const int r = rand()%N;
		if(vec[r])
		{
			delete vec[r];
			vec[r] = 0;
		}
		else
		{
			vec[r] = new AllocationTestStruct;
		}
	}

	LONGLONG clock1 = t.TimeElapsedMicroSec();

	for(size_t i=0; i<N; ++i)
		vec[i] = 0;

	t.Start();
	for(size_t j = 0; j<M ; ++j)
	{
		const int r = rand()%N;
		if(vec[r])
		{
			MM_DELETE ( vec[r] );
			vec[r] = 0;
		}
		else
		{
			vec[r] = MM_NEW ( AllocationTestStruct );
		}
	}

	LONGLONG clock2 = t.TimeElapsedMicroSec();

	std::cout << "first: " << clock1 << " second: " << clock2 << std::endl;
}

};